﻿using System;
using SuperSocket.SocketBase;
using SuperSocket.SocketBase.Protocol;
using VswService_V7.Utility;

namespace VswService_V7.Sok
{
    public class VswSession : AppSession<VswSession>
    {
        //user level
        //1 = OPERATOR can only watch
        //2 = ENGINEER production engineer, can modify order sequence and create order
        //3 = PROCESS process engineer can modify and create RECIPE
        //4 = MANAGER Production person in charge, can modify ORDER, RECIPE and team information
        //5 = ADMINISTRATOR The administrator can only manage personnel (adjust levels and add and delete users) and modify team information
        public int UserLevel
        {
            get;
            set;
        }

        //user name ip:port
        public string Name
        {
            get;
            set;
        }

        protected override void OnSessionStarted()
        {
            //this.Send("CONNECTED;1;"+this.Name+"##");
            this.Send("CONNECTED;" + DateTime.Now.ToString(Formats.DataFormat) + ";1;" + this.Name + "##");
        }

        protected override void HandleUnknownRequest(StringRequestInfo requestInfo)
        {
            //this.Send("UNKNOW;"+ requestInfo.ToString()+ "##");
            this.Send("UNKNOW;" + DateTime.Now.ToString(Formats.DataFormat) + ";-1;" + "unknowRequest##");
        }

        protected override void HandleException(Exception e)
        {
            //this.Send("ERROR;{0}##", e.Message);
            this.Send("ERROR;" + DateTime.Now.ToString(Formats.DataFormat) + ";-1;" + e.Message + "##");
        }

        protected override void OnSessionClosed(CloseReason reason)
        {
            //add you logics which will be executed after the session is closed
            //Consider the situation where SESSION is closed but the task has not been completed
            base.OnSessionClosed(reason);
        }
    }
}
